﻿/*TODO:不要在往这个文件里加代码，待重构*/

function inheritGlobalVars(window, parent) {
    /* https://github.com/hulang1024/notes/blob/master/about-iframe.md */
    /* 继承父级window全局变量 */
    [/*'require', 'define',*/
        'moment', '_', 'Signal',
     'sysDicts', 'sysFormatters', 'Dict', 'DictItem', 'DictMan',
     'openTab',
     'submitForm', 'formSubmit', 'str2Json',
     'getModuleContext', 'closeCurrentModule', 'openModuleByCode',
     'UI'
     ].forEach(function(name) {
        window[name] = parent[name];
    });
    
    extendLang(window);
    window.jqueryExtend(window.$);
    top.UI(window);

    window.post = function (url, data, success, dataType) {
        if (!dataType) {
            dataType = "json";
        }
        if (!success) {
            success = new Function();
        }
        window.$.ajax({
            type:"POST",
            url:url,
            traditional:true,
            data:data,
            dataType:dataType,
            success:success,
            async:false
        });
    }
    
    window.get = function(url, data, success) {return window.$.get('/' + url, data, success);}
}
extendLang(window);

/*
获取模块上下文,这里的模块是iframe
@param moduleCode 模块编码
*/
function getModuleContext(moduleCode, parent) {
    var iframe = (parent || window.top).document.querySelector('[id="module-iframe-' + moduleCode + '"]');
    return iframe ? iframe.contentWindow : null;
}
function closeCurrentModule() {}
function extendLang(window) {
    var String = window.String;
    String.prototype.replaceAll = function (szDir, szTar) {
        return this.replace(new RegExp(szDir, "g"), szTar);
    }
}
function str2Json(str) { return new Function("return " + str)(); }
